﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.Windows.Forms;

namespace MobileInterviewer
{
    static class Program
    {
        public const byte helloFormState = 0;
        public const byte startFormState = 1;
        public const byte nodeListState = 2;
        public const byte mainFormState = 3;
        
        private static HelloForm helloForm = null;
        private static MainForm mainForm = null;
        private static StartForm startForm = null;
        private static NodeList nodeList = null;
        public static int nodeID;
        public static int netID;
        public static byte cur_state;


        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [MTAThread]
        static void Main()
        {
            helloForm = new HelloForm();
            Application.Run(helloForm);
        }

        public static void Exit()
        {
            Application.Exit();
        }

        public static void toHelloForm()
        {
            if (helloForm == null)
            {
                helloForm = new HelloForm();
            }
            helloForm.Show();
            
            if (mainForm != null)
            {
                mainForm.Hide();
                mainForm = null;
            }
            if (startForm != null)
            {
                startForm.Hide();
            }
            if (nodeList != null)
            {
                nodeList.Hide();
            }
        }

        public static void toMainForm()
        {
            if (mainForm == null)
            {
                mainForm = new MainForm();
            }
            mainForm.Show();
            if (helloForm != null)
            {
                helloForm.Hide();
            }
            if (startForm != null)
            {
                startForm.Hide();
            }
            if (nodeList != null)
            {
                nodeList.Hide();
            }
        }

        public static void toStartForm()
        {
            if (startForm == null)
            {
                startForm = new StartForm();
            }
            startForm.Show();
            if (helloForm != null)
            {
                helloForm.Hide();
            }
            if (mainForm != null)
            {
                mainForm.Hide();
            }
            if (nodeList != null)
            {
                nodeList.Hide();
            }
        }

        public static void toNodeList(int nodeID, int netID)
        {
            if (nodeList == null)
            {
                nodeList = new NodeList(nodeID, netID);
            }
            nodeList.Show();
            if (helloForm != null)
            {
                helloForm.Hide();
            }
            if (mainForm != null)
            {
                mainForm.Hide();
            }
            if (startForm != null)
            {
                startForm.Hide();
            }
        }

        public static void setState(byte state)
        {
            switch (state)
            {
                case helloFormState:
                    helloForm = new HelloForm();
                    helloForm.Show();
                    break;
                case startFormState:
                    startForm = new StartForm();
                    startForm.Show();
                    break;
                case nodeListState:
                    nodeList = new NodeList(nodeID, netID);
                    nodeList.Show();
                    break;
                case mainFormState:
                    mainForm = new MainForm();
                    mainForm.Show();
                    break;
            }
            switch (cur_state)
            {
                case helloFormState:
                    helloForm.Hide();
                    helloForm = null;
                    break;
                case startFormState:
                    startForm.Hide();
                    startForm = null;
                    break;
                case nodeListState:
                    nodeList.Hide();
                    nodeList = null;
                    break;
                case mainFormState:
                    mainForm.Hide();
                    nodeList = null;
                    break;
            }
            cur_state = state;
            System.GC.Collect();
        }
    }
}